package com.xiaohe66.web.gateway.http.love;

import com.xiaohe66.common.value.R;
import com.xiaohe66.common.util.Assert;
import com.xiaohe66.web.application.love.WishAppService;
import com.xiaohe66.web.application.love.bo.WishListBo;
import com.xiaohe66.web.application.love.bo.WishSaveBo;
import com.xiaohe66.web.application.love.result.WishListResult;
import com.xiaohe66.web.application.love.result.WishResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohe
 * @since 2022.03.29 16:14
 */
@RestController
@RequestMapping("/love/wish")
@RequiredArgsConstructor
@Slf4j
public class WishController {

    private final WishAppService appService;

    @PostMapping
    public R<WishResult> save(@RequestBody WishSaveBo bo) {

        return R.ok(appService.create(bo));
    }

    @PutMapping
    public R<WishResult> update(@RequestBody WishSaveBo bo) {

        Assert.requireNotNull(bo.getId());

        return R.ok(appService.modify(bo));
    }

    @GetMapping
    public R<List<WishListResult>> list(WishListBo bo) {

        return R.ok(appService.list(bo));
    }

    @GetMapping("/{id}")
    public R<WishResult> detail(@PathVariable Long id) {

        WishResult result = appService.detail(id);

        return R.ok(result);
    }
}
